<?php

/**
 * 生活服务用户中心管理控制器
 *  
 */
class ServiceAction extends UserAction {

    public function index() {
        $this->display();
    }

    public function fabu() {
        if (IS_POST) {
            //校验敏感词
            $checkTitle = D('Badword')->checkBadword($_POST['info']);
            if ($checkTitle['status'] == false) {
                $this->error('自我介绍包含敏感词 -- ' . $checkTitle['data']);
            }

            //图片上传
            $savePath         = "/Public/Uploads/" . date("Ymd") . "/";
            $file             = $this->upload($savePath);
            $_POST['pic_url'] = $savePath . $file['pic_url']['savename'];
            $fabu             = D('Service')->fabu($_POST);
            if ($fabu['status'] == true) {
                $this->success('生活服务发布成功');
            } else {
                $this->error('生活服务发布失败' . $fabu['msg']);
            }
            exit;
        } else {
            //名片模版列表
            $themes = M('CardTheme')->select();
            //服务类别
            $cats   = M('ServiceCat')->select();
            $this->assign('cat', $cats);
            $this->assign('list', $themes);
            $this->display();
        }
    }

    public function slist() {
        $uid   = session('uid');
        $model = M('Service');

        $map = array();
        $map['s.user_id'] = $uid;

        //取得满足条件的记录数
        $count = $model
                ->join('AS s JOIN ' . C('DB_PREFIX') . 'service_cat AS c ON s.cat_ids = c.cat_id')
                ->where($map)
                ->count();
        if ($count > 0) {
            import("ORG.Util.Page");

            $limit = 8;
            $order = 's.create_time DESC';
            //创建分页对象
            $p     = new Page($count, $limit);
            //分页查询数据

            $voList = $model
                    ->where($map)
                    ->join('AS s JOIN ' . C('DB_PREFIX') . 'service_cat AS c ON s.cat_ids = c.cat_id')
                    ->order($order)
                    ->field('s.*, c.title as cname')
                    ->limit($p->firstRow . ',' . $p->listRows)
                    ->select();
            //分页模版
            $TP     = '共有{recordcount}{prev}&nbsp;{liststart}{list}&nbsp;{next}';
            $p->SetPager('default', $TP, array("listlong"      => "6", "first"         => "首页", "last"          => "尾页", "prev"          => "上一页", "next"          => "下一页", "list"          => "*", "disabledclass" => ""));

            //分页显示
            $page = $p->show();
            //模板赋值显示
            $data = array(
                'list'      => $voList,
                'page'      => $page,
                'nowPage'   => $_REQUEST['page'],
                'totalPage' => round($count / $limit),
            );
        }

        //推荐信息
        $roundDZ = _roundDazhe();
        $this->assign('rounddz', $roundDZ);
        $this->assign('data', $data);
        $this->display();
    }

}

?>
